package com.zf.yichat.utils.common;

import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 一句话描述功能
 *
 * @author fengsong
 * @date create in 08:36 2019/1/14 2019
 */
public class ValidUtils {

    public static boolean isUrl(String url) {
        if (Objects.isNull(url)) {
            return false;
        }
        String regex = "(((https|http)?://)?([a-z0-9]+[.])|(www.))"
                + "\\w+[.|\\/]([a-z0-9]{0,})?[[.]([a-z0-9]{0,})]+((/[\\S&&[^,;\u4E00-\u9FA5]]+)+)?([.][a-z0-9]{0,}+|/?)";
        //设置正则表达式
        Pattern pat = Pattern.compile(regex.trim());
        //比对
        return pat.matcher(url.trim()).matches();


    }

    /**
     * 是否淘口令 是则返回匹配的淘口令，否则返回null
     *
     * @param tkl
     * @return
     */
    public static String isTkl(String tkl) {
        String pattern = "([\\p{Sc}])\\w{8,12}([\\p{Sc}])";
        //设置正则表达式
        Pattern pat = Pattern.compile(pattern);
        Matcher m = pat.matcher(tkl);
        if (m.find()) {
            return m.group();
        }
        return null;
    }
}
